define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wanlshop/offline_order/index' + location.search,
                    add_url: 'wanlshop/offline_order/add',
                    edit_url: 'wanlshop/offline_order/edit',
                    del_url: 'wanlshop/offline_order/del',
                    multi_url: 'wanlshop/offline_order/multi',
                    import_url: 'wanlshop/offline_order/import',
                    table: 'wanlshop_offline_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('用户信息'), formatter: function (value, row, index) {
                            let user = row.user;
                            if(user){

                                return `<di>ID：${user.id}</div><div>昵称：${user.nickname}</div>`;
                            }else{
                                return row.user_id
                            }
                        }},
                        {field: 'order_id', title: __('订单信息'), formatter: function (value, row, index) {
                            let order = row.order;
                            if(order){
                                return `<di>ID：${order.id}</div><div>订单号：${order.order_no
                                }</div>`;
                            }else{
                                return row.order_id
                            }

                        }},
                        {field: 'shop_id', title: __('线下门店'), formatter: function (value, row, index) {
                            let shop = row.shop;
                            if(shop){

                                return `<di>ID：${shop.id}</div><div>名称：${shop.shopname
                                }</div>`;
                            }else{
                                return row.shop_id
                            }
                        }},
                        {field: 'pay_amount', title: __('订单支付金额'), operate:'BETWEEN'},
                        {field: 'amount', title: __('上级代理商佣金'), operate:'BETWEEN'},
                        {field: 'status', title: __('支付状态'), searchList: {"0":__('待支付'),"1":__('支付成功'),"2":__('支付失败')}, formatter: Table.api.formatter.status},
                        {field: 'created_at', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'pay_at', title: __('支付时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
